import { request } from '@/utils/request'
import type {
  ConsultOrderItem,
  FollowType,
  Image,
  KnowledgePage,
  KnowledgeParams,
  PageParams,
  PartialConsult,
  TopDep
} from '@/types/consult'
import type { DoctorPage } from '@/types/consult'

/**
 * 获取首页知识列表
 * @param params 对象 KnowledgeParams
 */
export const getKnowledgePage = (params: KnowledgeParams) =>
  request<KnowledgePage>('/patient/home/knowledge', 'GET', params)

/**
 * 获取关注医生
 * @param params PageParams
 */
export const getDoctorPage = (params: PageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', params)

/**
 * 关注接口
 * @param id 关注的 id
 * @param type 类型 FollowType
 */
export const followTarget = (id: string, type: FollowType = 'doc') =>
  request('/like', 'POST', { id, type })

/**
 * 获取所有科室
 */
export const getAllDep = () => request<TopDep[]>('/dep/all')

/**
 * 上传文件
 * @param file File
 */
export const uploadImage = (file: File) => {
  // 一般上传文件到后端，一般接收两种格式：第一种是 formData，第二种是 base64
  const f = new FormData()
  // key => file 是后端规定好的
  f.append('file', file)
  return request<Image>('/upload', 'POST', f)
}

import type {
  ConsultOrderPreData,
  ConsultOrderPreParams
} from '@/types/consult'

/**
 * 获取支付信息
 * @param params ConsultOrderPreParams
 */
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

/**
 * 生成订单编号/ID
 * @param data 收集到的所有数据
 */
export const createConsultOrder = (data: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', data)

/**
 * 获取支付地址的接口
 * @param params 对象
 */
export const getConsultOrderPayUrl = (params: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)

/**
 * 问诊室获取详情的接口
 * @param orderId 订单 ID
 */
export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })
